package com.notary.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.notary.config.NotaryProperties;
import com.notary.entity.Notary;
import com.notary.entity.SysUser;
import com.notary.entity.vo.JsonResult;
import com.notary.mapper.NotaryMapper;
import com.notary.mapper.SysUserMapper;
import com.notary.service.NotaryService;
import com.notary.service.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 系统用户 服务实现类
 * </p>
 *
 * @author xujun
 * @since 2020-07-28
 */
@Service("sysUserService")
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Resource
    SysUserMapper sysUserMapper;

    @Override
    public Page<SysUser> findAllAndPage(Page<SysUser> page, SysUser sysUser) {
        return sysUserMapper.findAllAndPage(page, sysUser);
    }


    @Override
    public JsonResult updatePassword(SysUser user) {
        if (user.getUserId() == null) {
            return JsonResult.fail("userId不能为空");
        }
        if (StringUtils.isEmpty(user.getPassword())) {
            return JsonResult.fail("Password不能为空");
        }
        SysUser user1 = this.getById(user.getUserId());
        user1.setPassword(SecureUtil.md5(user.getPassword()));
        this.updateById(user1);
        return JsonResult.success();
    }
}
